<?php
require_once 'config.php';
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title><?php echo $title; ?></title>
</head>

<body>
    <div class="header">
        <h1 class="title">
            <?php echo $title; ?>

        </h1>
        <!-- <p>please fill all the texts in the fields</p> -->
        <div class="xie">
            <div class="gray">
                <!-- <h2>写留言</h2> -->
                <p class="p">please fill all the texts in the fields！！！</p>
                <form action="add.php" method="get">
                    <p>Your Name：<input type="text" name="name" placeholder="你的姓名"></p>
                    <p>QQ：<input type="text" name="qq" placeholder="你的qq呀"></p>
                    <p>Message：</p>
                    <textarea name="text" cols="30" rows="10" placeholder="说点什么..."></textarea>

                    <p><input class="submit" type="submit" value="发表"></p>
                </form>
            </div>
        </div>
    </div>
    <hr>

    <h2 class="li">留言列表</h2>
    <ul>
        <?php
        // 最新留言展示前面
        $sql = "SELECT * FROM `liuyan` ORDER BY `liuyan`.`id` DESC";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            // 输出数据
            while ($row = $result->fetch_assoc()) {
        ?>
                <li>
                    <img src="http://q1.qlogo.cn/g?b=qq&nk=<?php echo $row["qq"]; ?>&s=640" alt="">
                    <p><?php echo $row["id"]; ?>楼</p>
                    <p>留言内容：<?php echo $row["text"]; ?></p>
                    <p>留言人：<?php echo $row["name"]; ?></p>
                    <p>QQ：<?php echo $row["qq"]; ?></p>
                    <p>留言时间：<?php echo $row["time"]; ?></p>
                    <p class="b">
                        <a href="edit.php?id=<?php echo $row['id']; ?>">编辑</a>
                        <a href="del.php?id=<?php echo $row['id']; ?>">删除</a>
                    </p>
                </li>
        <?php
            }
        } else {
            echo "暂无留言";
        }
        ?>
    </ul>

    <div class="footer">—————————— END ——————————</div>
</body>

</html>